package net.xiduth.events.button;

import net.xiduth.events.ButtonEvent;
import net.xiduth.events.EventManager;
import net.xiduth.game.item.Item;
import net.xiduth.game.player.Player;
import net.xiduth.net.decoders.handlers.ButtonHandler;

/**
 * The class handling the buttons on the equipment stats bonuses screen.
 * 
 * @author Tyluur <ItsTyluur@Gmail.com>
 * @since July 22nd, 2012
 */
public final class EquipmentBonusesEvent implements ButtonEvent {

	@Override
	public boolean init() {
		return EventManager.register(667, this);
	}

	@Override
	public boolean handle(Player player, int interfaceId, int buttonId,
			int packetId, int slotId, int slotId2) {
		Item item = player.getEquipment().getItem(slotId);
		if (player.getInventory().getFreeSlots() > 0) {
			if (item != null) {
				player.getEquipment().deleteItem(item.getId(), item.getAmount());
				player.getInventory().addItem(item);
				player.getAppearence().generateAppearenceData();
				if (ButtonHandler.sendWear(player, slotId, item.getId()))
					ButtonHandler.refreshEquipBonuses(player);
			}
		} else {
			player.sendMessage("Not enough space in your inventory.");
		}
		return true;
	}

}
